package org.brisling.authorize.shiro;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.brisling.sysman.domain.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * 
 * shiro当前用户filter
 * @author : jackson wang
 * @Date   : 2015年10月8日 下午10:01:07
 * @version: 1.0
 * 
 */
@Component
public class CurrentUserInterceptor extends HandlerInterceptorAdapter{
	
	@Autowired
	private ShiroSecurityService securityService;
   
    

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        // Add the current user into the request
    	
    	Users currentUser = securityService.getCurrentUser();
        if( currentUser != null ) {
            httpServletRequest.setAttribute( "currentUser", currentUser );
        }
    }
}
